﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QUANLYBANSACH_ET;

namespace QUANLYBANSACH_DAL
{
    public class DAL_SACH
    {
        public static DataTable getSach()
        {
            SqlConnection con = SqlConnectionData.connect();
            SqlCommand cmd = new SqlCommand("SELECT * FROM [SACH]", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            SqlConnectionData.disconnect(con);
            return dt;
        }

        public static void insertSACH(ET_SACH sach)
        {
            SqlConnection con = SqlConnectionData.connect();
            SqlCommand cmd = new SqlCommand("Proc_InsertSACH", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@maSach", SqlDbType.Char, 7);
            cmd.Parameters.Add("@tenSach", SqlDbType.NVarChar, 30);
            //Gán giá trị
            cmd.Parameters["@maSach"].Value = sach.MaSach;
            cmd.Parameters["@tenSach"].Value = sach.TenSach;
            con.Open();
            cmd.ExecuteNonQuery();
            SqlConnectionData.disconnect(con);
        }

        public static void updateSACH(ET_SACH sach)
        {
            SqlConnection con = SqlConnectionData.connect();
            SqlCommand cmd = new SqlCommand("Proc_UpdateSACH", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@maSach", SqlDbType.Char, 7);
            cmd.Parameters.Add("@tenSach", SqlDbType.NVarChar, 30);
            //Gán giá trị
            cmd.Parameters["@maSach"].Value = sach.MaSach;
            cmd.Parameters["@tenSach"].Value = sach.TenSach;
            con.Open();
            cmd.ExecuteNonQuery();
            SqlConnectionData.disconnect(con);
        }

        public static void deleteSACH(String maSach)
        {
            SqlConnection con = SqlConnectionData.connect();
            SqlCommand cmd = new SqlCommand("Proc_DeleteSACH", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@maSach", SqlDbType.Char, 7);
            //Gán giá trị
            cmd.Parameters["@maSach"].Value = maSach;
            con.Open();
            cmd.ExecuteNonQuery();
            SqlConnectionData.disconnect(con);
        }
    }
}
